package xworker.gluon.glisten.mvc;

import com.gluonhq.charm.glisten.mvc.SplashView;
import javafx.util.Duration;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.util.JavaFXUtils;

public class SplashViewActions {
    public static void init(SplashView view, Thing thing, ActionContext actionContext){
        ViewActions.init(view, thing, actionContext);
    }

    public static Object create(ActionContext actionContext){
        Thing self = actionContext.getObject("self");

        String nextView = JavaFXUtils.getString(self, "nextView", actionContext);
        Duration duration = JavaFXUtils.getDuration(self, "duration", actionContext);

        SplashView view = nextView != null && !nextView.isEmpty() ? new ThingSplashView(nextView, self, actionContext) : new ThingSplashView(self, actionContext);
        init(view, self, actionContext);
        actionContext.g().put(self.getMetadata().getName(), view);

        actionContext.peek().put("parent", view);
        for(Thing child : self.getChilds()){
            child.doAction("create", actionContext);
        }

        return view;
    }
}
